import { localCache } from '@/utils/cache'
import { BASE_URL, TIME_OUT } from './config'
import HYRequest from './request'

const hyRequest = new HYRequest({
  baseURL: BASE_URL,
  timeout: TIME_OUT,
  withCredentials: true, // 允许携带cookie等凭证
  interceptors: {
    requestSuccessFn: (config) => {
      const token = localCache.getCache('token')
      if (token && config.headers) {
        config.headers.saToken = token
      }
      return config
    },
  },
})

export default hyRequest
